import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      home: ScaffoldRoute(),
    );
  }
}

class ScaffoldRoute extends StatefulWidget {
  @override
  _ScaffoldRouteState createState() => _ScaffoldRouteState();
}

class _ScaffoldRouteState extends State<ScaffoldRoute> {
  int _selectIndex = 1;
  var pages = ['home', "school", "business"];
  final List<Widget> chiledList = [HomeClass(), SchoolClass(), BusinessClass()];

  int _counter = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text("MY APP"), actions: <Widget>[
          IconButton(
            icon: Icon(Icons.share),
            onPressed: () {
              Scaffold.of(context).openDrawer();
            },
          )
        ]),
        drawer: MyDrawer(), //抽屉
        // body: Center(
        //   child: Column(
        //     mainAxisAlignment: MainAxisAlignment.center,
        //     children: <Widget>[
        //       Text(
        //         'You have pushed the button this many times:',
        //       ),
        //       Text(
        //         '$_counter',
        //         style: Theme.of(context).textTheme.headline4,
        //       ),
        //     ],
        //   ),
        // ),
        body: chiledList[_selectIndex],
        bottomNavigationBar: BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(icon: Icon(Icons.home), label: pages[0]),
            BottomNavigationBarItem(
                icon: Icon(Icons.business), label: pages[1]),
            BottomNavigationBarItem(icon: Icon(Icons.school), label: pages[2]),
          ],
          currentIndex: _selectIndex,
          fixedColor: Colors.blue,
          onTap: _onItemTapped,
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: _onAdd,
        ));
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectIndex = index;
    });
  }

  void _onAdd() {
    print("此处打印输出");
    setState(() {
      _counter++;
    });
  }
}

class MyDrawer extends StatelessWidget {
  const MyDrawer({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
        child: MediaQuery.removePadding(
      context: context,
      removeTop: true,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(top: 38.0),
            child: Row(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16.0),
                  child: ClipOval(
                      child: Image.asset("../web/icons/avatar.png", width: 80)),
                ),
                Text(
                  "Wendux",
                  style: TextStyle(fontWeight: FontWeight.bold),
                )
              ],
            ),
          ),
          Expanded(
              child: ListView(
            children: <Widget>[
              ListTile(
                leading: const Icon(Icons.add),
                title: const Text("Add account"),
              ),
              ListTile(
                leading: const Icon(Icons.settings),
                title: const Text("Message account"),
              )
            ],
          ))
        ],
      ),
    ));
  }
}

class PageControl extends StatelessWidget {
  const PageControl({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Code Sample for Navigator',
      // MaterialApp contains our top-level Navigator
      routes: <String, WidgetBuilder>{
        '/home': (BuildContext context) => const SignUpPage(),
      },
    );
  }
}

class SignUpPage extends StatelessWidget {
  const SignUpPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Navigator(
      initialRoute: "/home",
      onGenerateRoute: (RouteSettings settings) {
        WidgetBuilder builder;
        switch (settings.name) {
          case "home":
            builder = (BuildContext context) => HomeClass();
            break;
          case "school":
            builder = (BuildContext context) => SchoolClass();
            break;
          case "business":
            builder = (BuildContext context) => BusinessClass();
            break;
          default:
            throw Exception('Invalid route : ${settings.name}');
        }
      },
    );
  }
}

class HomeClass extends StatefulWidget {
  @override
  _HomeRouteState createState() => _HomeRouteState();
}

class _HomeRouteState extends State<HomeClass> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("home"),
    );
  }
}

class SchoolClass extends StatefulWidget {
  @override
  _SchoolRouteState createState() => _SchoolRouteState();
}

class _SchoolRouteState extends State<SchoolClass> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("school"),
    );
  }
}

class BusinessClass extends StatefulWidget {
  @override
  _BusinessRouteState createState() => _BusinessRouteState();
}

class _BusinessRouteState extends State<BusinessClass> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text("business"),
    );
  }
}
